package com.aiatomic.couting.templates;

import java.util.ArrayList;
import java.util.List;

import com.aiatomic.couting.models.TemplateEntity;

public class TemplateChangeEventDispatcher {
	public static final int EVENT_CODE_ADD = 0;
	public static final int EVENT_CODE_REMOVE = 1;
	private static TemplateChangeEventDispatcher _instance;
	private List<ITemplateChangeEventListener> listenters;

	private TemplateChangeEventDispatcher() {
		listenters = new ArrayList<ITemplateChangeEventListener>();
	}

	public static TemplateChangeEventDispatcher getInstance() {
		if (_instance == null) {
			_instance = new TemplateChangeEventDispatcher();
		}
		return _instance;
	}

	public void dispatchEvent(TemplateEntity entity, int eventCode) {
		for (ITemplateChangeEventListener listen : listenters) {
			listen.onTemplateChangeEvent(entity, eventCode);
		}
	}

	public void registListener(ITemplateChangeEventListener listener) {
		listenters.add(listener);
	}

	public void removeListener(ITemplateChangeEventListener listener) {
		if (listenters.contains(listener))
			listenters.remove(listener);
	}

	public void clean() {
		listenters.clear();
	}
}
